﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SDT.Model;
using SDT.Mobile.Models;

namespace SDT.Mobile.Controllers
{
    public class AjaxDataController : Controller
    {
        //
        // GET: /AjaxData/

        public ActionResult Index()
        {
            return View();
        }
        SDTDataContext eDataContext = new SDTDataContext();

        public ActionResult GetDistrict(int id)
        {
            try
            {
                var d = eDataContext.Districts.Where(e => e.CityID == id).ToList();
                return View(d);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 404;
                Response.Write(ex.Message);
                throw ex;
            }
        }
        public ActionResult GetProductCategoryByType(int id)
        {
            try
            {
                List<ProductCategory> proCat = eDataContext.ProductCategories
                                                .Where(c => c.TypeID.HasValue && c.TypeID.Value == id &&
                                                            c.ActiveYN.HasValue && c.ActiveYN.Value == true)
                                                .ToList();
                return View(proCat);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 404;
                Response.Write(ex.Message);
                throw ex;
            }
        }
        /// <summary>
        /// Vietlv
        /// Get list DemandCategory
        /// </summary>
        public ActionResult GetDemandCategoryByType(int id)
        {
            try
            {
                List<DemandCategory> DemaCat = eDataContext.DemandCategories
                                                .Where(e => e.DemandTypeID.HasValue && e.DemandTypeID.Value == id &&
                                                       e.ActiveYN.HasValue && e.ActiveYN.Value == true)
                                                .ToList();
                return View(DemaCat);
            }
            catch (Exception exp)
            {
                Response.StatusCode = 404;
                Response.Write(exp.Message);
                throw exp;
            }
        }
        public ActionResult GetPrice(int id)
        {
            try
            {
                List<ConvertPrice> p = eDataContext.ConvertPrices
                                                .Where(c => c.TypeID == id)
                                                .ToList();
                return View(p);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 404;
                Response.Write(ex.Message);
                throw ex;
            }
        }
        public ActionResult GetArea(int id)
        {
            try
            {
                List<ConvertArea> p = eDataContext.ConvertAreas
                                                .Where(c => c.TypeID == id)
                                                .ToList();
                return View(p);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 404;
                Response.Write(ex.Message);
                throw ex;
            }
        }
        public ActionResult GetProjectByDistrict(int id)
        {
            try
            {
                List<Project> proj = eDataContext.Projects
                                                .Where(p => p.DistrictID == id && p.PubYN == true)
                                                .ToList();

                return View(proj);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 404;
                Response.Write(ex.Message);
                throw ex;
            }
        }       
    }
}
